/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cabarrus.xltosql.util;

import com.cabarrus.xltosql.XLToSQLApp;
import java.awt.Frame;
import java.io.File;
import java.io.IOException;
import javax.swing.JOptionPane;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import org.jdesktop.application.Application;

/**
 *
 * @author moscac
 */
public class Utility {

    public static Workbook getWorkbook() {
        Workbook workbook = null;
        String fileName = FileUtility.chooseFile(null, ".", "Select Excel File");
        if (fileName.length() >= 0) {
            try {
                workbook = Workbook.getWorkbook(new File(fileName));
            } catch (IOException ioe) {
                JOptionPane.showMessageDialog(null, "Exception opening file " +
                        fileName + ": " + ioe.getMessage());
            } catch (BiffException be) {
                JOptionPane.showMessageDialog(null, "Exception opening file " +
                        fileName + ": " + be.getMessage());
            }
        }
        return workbook;
    }

    public static boolean isTaskRunning(String taskTitle) {
        return isTaskRunning(taskTitle, false, null);
    }

    public static boolean isTaskRunning(String taskTitle,
            boolean showMessage, Frame parent) {
        if (Application.getInstance(XLToSQLApp.class).isTaskRunning(taskTitle)) {
            if (showMessage) {
                JOptionPane.showMessageDialog(parent, taskTitle + " is already running.");
            }
            return true;
        }
        return false;
    }
}
